package com.example.springboot2022nocv.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.springboot2022nocv.entity.User;
import com.example.springboot2022nocv.mapper.RoleMapper;
import com.example.springboot2022nocv.mapper.UserMapper;
import com.example.springboot2022nocv.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 程序员小洋
 * @version 2022.3
 * @date 2022/12/28 10:24
 * @title
 */
@SuppressWarnings("all")
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public User login(String username, String password) {
        User user = userMapper.login(username, password);
        return user;
    }

    @Override
    public void saveUserRole(Integer uid, Integer[] ids) {
        roleMapper.deleteRoleUserByUid(uid);
        if (ids!=null&&ids.length>0){
            for (Integer rid : ids) {
                roleMapper.saveUserRole(uid, rid);
            }
        }
    }
}
